<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="场站名称" prop="stationName">
        <el-input
          v-model="queryParams.stationName"
          placeholder="请输入场站名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="场站编号" prop="stationCode">
        <el-input
          v-model="queryParams.stationCode"
          placeholder="请输入场站编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item  label="所属区域" prop="areaCode">
        <el-select v-model="queryParams.areaCode"  placeholder="请选择">
          <el-option
            v-for="item in jurisdictionUnitData"
            :key="item.areaCode"
            :label="item.areaName"
            :value="item.areaCode"
          ></el-option>
        </el-select>
      </el-form-item>


      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="stationList" :max-height="tableHeight">
      <el-table-column  width="10" align="center" />
      <el-table-column label="场站名称" align="left" prop="stationName" width="250px" />
      <el-table-column label="联系人" align="center" prop="contacts" />
      <el-table-column label="联系电话" align="center" prop="telephone" />
      <el-table-column label="联系地址" align="left" prop="address" width="310px" :show-overflow-tooltip="true"/>
      <el-table-column label="所属区域" align="center" prop="jurisdictionUnit" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">

          <el-button
            size="mini"
            type="text"
            icon="el-icon-odometer"
            @click="handleManagement(scope.row)"
          >管理制度</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
  import { listStation, getStation, delStation, addStation, updateStation, exportStation,getTown,getVideoPath, getAreaListByUserId } from "@/api/weight/station";
  import { getToken } from "@/utils/auth";

  export default {
    name: "Station",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        tableHeight: window.innerHeight - 275,
        // 总条数
        total: 0,
        // 场站信息表格数据
        stationList: [],
        // 台账信息表格数据
        ledgerList: [],
        // 弹出层标题
        title: "",
        //字典-是否是
        dict_allPermissions: [],
        // 管辖单位
        jurisdictionUnitData: [],
        //所属单位
        townData: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          stationName: undefined,
          stationCode: undefined,
          areaCode: undefined
        }
      };
    },
    created() {
      this.getList();

      this.getDicts("is_all_permissions").then(response => {
        this.dict_allPermissions = response.data;
      });

      getAreaListByUserId().then(response =>{
        this.jurisdictionUnitData=response.data;
      });
    },
    methods: {
      /** 查询场站信息列表 */
      getList() {
        this.loading = true;
        listStation(this.queryParams).then(response => {
          this.stationList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      /** 获取管辖地，属地 **/
      getTown(areaCode) {
        getTown(areaCode).then(response =>{
            this.townData=response.data;
        });
      },
      /** 管辖地选中 **/
      selectChanged(value) {
        this.getTown(value);
        this.form.town = null
      },
      visibleFormat(row, column) {
        return this.selectDictLabel(this.dict_allPermissions, row.isAllPermissions);
      },
      // 表单重置
      reset() {
        this.form = {
          id: undefined,
          stationName: undefined,
          stationCode: undefined,
          contacts: undefined,
          telephone: undefined,
          address: undefined,
          jurisdictionUnit: undefined,
          town: undefined,
          isAllPermissions: undefined,
          delFlag: undefined,
          createTime: undefined,
          createId: undefined,
          updateTime: undefined,
          updateId: undefined,
          remark: undefined,
          sealPath: '',
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      /** 选择管理制度 **/
      handleManagement(row) {
        this.$router.push({name: 'weightManagementView2', params: {stationId: row.id , stationName: row.stationName}})
      }
    }
  };
</script>

